<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/rp/common/taglib.jsp" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <base href="<%=basePath%>">
    
    <title>${ webpageTitle }</title>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
	
	<script src="rp/scripts/boot.js" type="text/javascript"></script>
	
	<style type="text/css">
	   	
    </style>
	
  </head>
  
  <body class="body-fit">
  	
  	<div style="width:100%;">
        <div class="mini-toolbar" style="padding:0px;border-top:0;border-left:0;border-right:0;">
            <table style="width:100%;">
                <tr>
                    <td style="width:100%;">
                        <a class="mini-button" iconCls="" onclick="addRootNode()"><i class="fa fa-plus fa-lg"></i> 添加根栏目</a>
			  			<a class="mini-button" iconCls="" onclick="addChildNode()"><i class="fa fa-plus fa-lg"></i> 添加子栏目</a>
				        <a class="mini-button" iconCls="" onclick="saveData()"><i class="fa fa-floppy-o fa-lg"></i> 保存</a>
				        <a class="mini-button mini-button-danger" iconCls="" onclick="removeRows()"><i class="fa fa-trash-o fa-lg"></i> 删除</a>       
                    </td>
                    <td style="white-space:nowrap;">
                    	
                    </td>
                </tr>
            </table>           
        </div>
    </div>
    <div class="mini-fit">
	  	<div id="channelTreeGrid" class="mini-treegrid" style="width: 100%; height: 100%;" borderStyle="border:0;"     
		    url="rp/infopub/channelMng/getChannels" showTreeIcon="true"
		    treeColumn="name" idField="id" parentField="pid" 
		    resultAsTree="false" expandOnLoad="true"
	   		allowCellEdit="true" allowCellSelect="true" multiSelect="true"
	       	editNextOnEnterKey="true" editNextRowCell="true" allowCellValid="true">
		    <div property="columns">
		        <div type="indexcolumn" headerAlign="center">序号</div>
		        <div type="checkcolumn" width="20"></div>
		        <div name="name" field="name" vtype="required" width="80" headerAlign="center">
		        	栏目名称<input property="editor" class="mini-textbox" style="width:100%;" />
		        </div>
		        <div name="remark" field="remark" headerAlign="center">
		        	备注<input property="editor" class="mini-textarea" style="width:200px;" minWidth="200" minHeight="50"/>
		        </div>
		        <div type="comboboxcolumn" autoShowPopup="true" 
		        	name="enabled2" field="enabled2" vtype="required" width="70" align="center" headerAlign="center" renderer="onEnabledRenderer">
		        	是否激活
	                <input property="editor" class="mini-combobox" style="width:100%;" data="Activates" />                
	            </div>
		        <div name="createDate" field="createDate" width="70" headerAlign="center" allowSort="true" renderer="onDateRenderer">
		        	创建日期
		        </div>                
		    </div>
		</div>
	</div>
  	
	<script type="text/javascript">
		var grid;
	
		$(function(){
			mini.parse();
			grid = mini.get("channelTreeGrid");
		});
		
		function addRootNode() {
            var newNode = { name: "" };
            grid.addNode(newNode, 2);
            grid.beginEditCell(newNode, "name");
        }
		
		function addChildNode(){
			var selectedNode = grid.getSelectedNode();
			if(!selectedNode){
				mini.alert("您未选中任何节点");
			}else{
				grid.expandNode(selectedNode);
				var newNode = { name: "" };
				grid.addNode(newNode, "add", selectedNode);
				grid.beginEditCell(newNode, "name");
			}
		}
		
		function saveData() {
        	grid.validate();
			if (grid.isValid() == false) {
                var error = grid.getCellErrors()[0];
                grid.beginEditCell(error.record, error.column);
                return;
            }
			var data = grid.getChanges();
            var json = mini.encode(data, "yyyy-MM-dd HH:mm:ss");
            grid.loading("保存中，请稍等......");
            rp_ajax("rp/infopub/channelMng/saveChannels", {data: json}, function(text){
            	grid.reload();
            });
        }
		
		function removeRows(){
			mini.confirm("确定删除记录吗？", "友情提示",
	            function (action) {
	                if (action == "ok") {
	                	var rows = grid.getSelecteds();
	                    var json = mini.encode(rows);
	                    if (rows.length > 0) {
	                    	rp_ajax("rp/infopub/channelMng/deleteChannels", {data: json}, function(text){
	                    		//grid.removeRows(rows, false);
	                    		grid.reload();
	                        });
	                    }
	                }
	            }
	        );
		}
	</script>
  </body>
</html>
